<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/5/27
 * Time: 10:32
 */

namespace Home\Service;


use Common\Common\Service;
use Home\Component\ActComponent;
use Home\Exception\HomeException;
use Home\Request\Apply\ActApplyTimeRequest;
use Home\Response\ActApplyTimeResponse;

class ActApplyTimeService implements Service
{
    public function run(ActApplyTimeRequest $request = null)
    {
        if ($request->issetActId() == false)
            throw new HomeException(10001);
        if ($request->verifyActId() == false)
            throw new HomeException(10002);
        if ($request->IsActIdInRange() == false)
            throw new HomeException(10003);

        $act_id = $request->getActId();
        $component = new ActComponent();
        $response = new ActApplyTimeResponse();
        try {
            $data = $component->getActApplyTime($act_id);
            if (is_null($data) == true) {
                $response->setItIsNull();
            } else {
                //dump($data);
                $response->setData($data);
            }
        } catch (HomeException $e) {
            throw new HomeException($e->getMessage(), $e->getCode());
        }
        return $response;
    }
}